//
//  WZToolBarView.swift
//  weibo
//
//  Created by mac on 16/3/7.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit
import SnapKit

enum WZbuttonType:Int {
    case recent = 10001
    case defalt = 10002
    case emoji = 10003
    case lxh = 10004
}

protocol WZToolBarViewDelegate:NSObjectProtocol{
    func changEmotionCellShow(buttonType:WZbuttonType)
}

class WZToolBarView: UIView {

    
    
    
    weak var delegate:WZToolBarViewDelegate?
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //    MARK:添加到父控件设置约束
    private func setupUI(){
        addSubview(recentBtn)
        addSubview(defaltBtn)
        addSubview(emojiBtn)
        addSubview(lxhBtn)
        
//        添加约束
        recentBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(defaltBtn.snp_width)
        }
        
        defaltBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(recentBtn.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            
            make.width.equalTo(emojiBtn.snp_width)
        }
        emojiBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(defaltBtn.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
         
            make.width.equalTo(lxhBtn.snp_width)
        }
        lxhBtn.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(emojiBtn.snp_right)
            make.top.equalTo(self.snp_top)
            make.bottom.equalTo(self.snp_bottom)
            make.right.equalTo(self.snp_right)
            
        }
        
        
    }
    
   @objc private func btnClick(btn:UIButton){
//    设置按钮只有一个被选中
        for subview in subviews{
            let btn = subview as! UIButton
            btn.selected = false
        }
        btn.selected = true
    
//    为按钮设置点击方法
    self.delegate?.changEmotionCellShow(WZbuttonType(rawValue: btn.tag)!)
    
    }
    
    
    //    MARK:懒加载4个按钮
    
    
    lazy var recentBtn:UIButton = UIButton(title: "最近", image: "compose_emotion_table_normal", selectedImage: "compose_emotion_table_selected", tag: WZbuttonType.recent.rawValue, target: self, action: "btnClick:")
    
    lazy var lxhBtn:UIButton = UIButton(title: "浪小花", image: "compose_emotion_table_normal", selectedImage: "compose_emotion_table_selected", tag: WZbuttonType.lxh.rawValue, target: self, action: "btnClick:")
    
    
     lazy var defaltBtn:UIButton = UIButton(title: "默认", image: "compose_emotion_table_normal", selectedImage: "compose_emotion_table_selected", tag: WZbuttonType.defalt.rawValue, target: self, action: "btnClick:")
    
     lazy var emojiBtn:UIButton = UIButton(title: "emoji", image: "compose_emotion_table_normal", selectedImage: "compose_emotion_table_selected", tag: WZbuttonType.emoji.rawValue, target: self, action: "btnClick:")
    
}
